<template lang="">
    <div>
        <el-table :data="userlist" border style="width: 100%">
    <el-table-column prop="uid" label="用户编号" width="200" />
    <el-table-column prop="username" label="用户昵称" width="130" />
    <el-table-column prop="rolename" label="所属角色" width="130" />
     <el-table-column prop="status" label="状态" width="180">
                <template #default="item">
                    <div>
                        <el-tag v-if="item.row.status == 1" type="success">启用</el-tag>
                        <el-tag v-else type="danger">禁用</el-tag>
                    </div>
                </template>

            </el-table-column>
    <el-table-column label="操作">
                <template #default="item">
                    <div>
                        <el-button type="primary" @click="edit(item.row.uid)">编辑</el-button>
                        <el-button type="danger" @click="del(item.row.uid)">删除</el-button>
                    </div>
                </template>
            </el-table-column>
  </el-table>

   <el-pagination
   :page-size="size"
    @current-change="changePage"
    small
    background
    layout="prev, pager, next"
    :total="total"
    class="mt-4"
  />
    </div>
</template>
<script lang="ts" setup>
import { getUserdelete } from '@/request/api'
import { defineEmits, computed } from 'vue'
import { ElMessageBox, ElMessage } from 'element-plus'
// 引入仓库方法
import { useStore } from 'vuex';

const store = useStore();
// 获取列表
const userlist = computed(() => store.getters["user/getUserList"])
console.log(userlist, 'userlist');
const getUser = () => {
    store.dispatch("user/changeUserAction")
}
// 组件一加载触发行动
getUser();
// 获取总页数
const total = computed(() => store.getters["user/getCount"])
console.log(total, 'total11111');
const getCount = () => {
    store.dispatch("user/getCountAction")
}
// 组件一加载触发行动
getCount()
// 获取页面显示的条数
const size = computed(() => store.getters["user/getSize"])
console.log(size, size);
// 页码点击事件
let changePage = (n:any) => {
    store.dispatch("user/getUserPageAction",n)
}
// 编辑
const emit = defineEmits(['edit'])
const edit = (id: any) => {
    emit('edit', id)
}
// 删除
let del = (uid: any) => {
    ElMessageBox.confirm(
        '你确定要删除这条信息吗?',

        {
            confirmButtonText: '确认',
            cancelButtonText: '取消',
            type: 'warning',
        }
    )
        .then(() => {
            getUserdelete({ uid: uid }).then(res => {
                console.log(res, '删除')
                if (res.code == 200) {
                    ElMessage.success(res.msg);
                    getUser()
                    getCount()
                } else {
                    ElMessage.error(res.msg)
                }
            })
        })
        .catch(() => {
            ElMessage({
                type: 'info',
                message: '已取消删除',
            })
        })
}
</script>
<style scoped>
.mt-4 {
    float: right;
    margin-right: 10px;
}
</style>